/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.gov.cemaden.library.dao.staff;

import br.gov.cemaden.library.dao.GenericDao;
import br.gov.cemaden.library.interfaces.staff.ExecucaoInterface;
import br.gov.cemaden.library.model.staff.Aplicacao;
import br.gov.cemaden.library.model.staff.Execucao;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author alan
 */
public class ExecucaoDao extends GenericDao implements ExecucaoInterface{

    Session session;
    
    public ExecucaoDao(Session session){
        this.session = session;
    }
    
    public Execucao findLastByAplicacao(Aplicacao aplicacao) {
        Execucao e = null;
        try{
            Query query = session.getNamedQuery("Execucao.findLastByAplicacao")
                    .setEntity("aplicacao", aplicacao);

            e = (Execucao) query.uniqueResult();
        }
        catch(HibernateException ex){
            throw new HibernateException(this.getClass().getName()+" findLastByAplicacao(Aplicacao aplicacao)", ex);            
        }
        return e;
    }
    
}
